package org.example.completed.controller;


import org.example.completed.domain.AdoptionCloudRecordDO;
import org.example.completed.domain.AdoptionCloudSituationDO;
import org.example.completed.model.vo.ResultVO;
import org.example.completed.service.AdoptionCloudRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 云领养成功记录表
 *
 * @since 2025-04-15
 */
@RestController
@RequestMapping("/adoptionCloudRecordDO")
public class AdoptionCloudRecordController {
    @Autowired
    private AdoptionCloudRecordService adoptionCloudRecordService;

    /**
     * 修改云领养记录的新名字
     * @param id 记录ID
     * @param newName 新的动物名字
     * @return 修改结果
     */
    @PostMapping("/updateNewName")
    public ResultVO<Boolean> updateNewName(@RequestParam String id, @RequestParam String newName) {
        boolean result = adoptionCloudRecordService.updateNewName(id, newName);
        if (result) {
            return ResultVO.ok();
        } else {
            return ResultVO.fail("修改失败");
        }
    }

    /**
     * 获取所有云领养记录
     * @return 所有云领养记录列表
     */
    @GetMapping("/getAllRecords")
    public ResultVO<List<AdoptionCloudRecordDO>> getAllRecords() {
        List<AdoptionCloudRecordDO> records = adoptionCloudRecordService.list();
        return ResultVO.ok(records);
    }

    /**
     * 查询单个云领养记录
     * @param id 记录ID
     * @return 云领养宠物近况实体
     */
    @GetMapping("/{id}")
    public ResultVO<AdoptionCloudRecordDO> getById(@PathVariable String id) {
        AdoptionCloudRecordDO adoptionCloudRecordDO = adoptionCloudRecordService.getById(id);
        return adoptionCloudRecordDO != null ? ResultVO.ok(adoptionCloudRecordDO) : ResultVO.fail(404, "未找到记录");
    }
}

